package cn.com.fuhuitong.main.home.adapter

import android.content.Context
import android.util.SparseBooleanArray
import android.view.View
import androidx.core.util.forEach
import cn.com.fuhuitong.R
import cn.com.fuhuitong.base.BaseDelegateAdapter
import cn.com.fuhuitong.main.ItemViewType
import cn.com.fuhuitong.utils.JsonUtils
import com.alibaba.android.vlayout.LayoutHelper
import com.blankj.utilcode.util.LogUtils
import kotlinx.android.synthetic.main.item_sign_in_date.view.*
import java.util.*


class SignInDateAdapter(
    private val mContext: Context,
    mHelper: LayoutHelper
) : BaseDelegateAdapter<String>(
    mContext = mContext,
    mHelper = mHelper,
    mLayoutId = R.layout.item_sign_in_date,
    mItemViewType = ItemViewType.SIGN_IN_DATE
) {

    private val sbArray = SparseBooleanArray()

    override fun onBindViewHolder(itemView: View, position: Int, itemData: String) {
        super.onBindViewHolder(itemView, position, itemData)
        itemView.text_sign_in_date_name.text = itemData
        if (position < 7) {
            itemView.text_sign_in_date_name.setTextColor(mContext.resources.getColor(R.color.colorMainAsh))
            itemView.text_sign_in_date_name.isEnabled = false
        } else {
            itemView.text_sign_in_date_name.isEnabled = isSelectedItem(position)
        }
        itemView.tag = position
    }

    /**
     * 根据位置判断条目是否选中
     * */
    private fun isSelectedItem(position: Int): Boolean {
        return sbArray.get(position)
    }

    fun setSelectedItem(positions: MutableList<Int>) {
        positions.forEach {
            this.sbArray.put(it, true)
        }
        this.notifyDataSetChanged()
    }
}